package io.github.controller.admin;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.plugins.Page;
import io.github.annotation.Log;
import io.github.entity.SysLogEntity;
import io.github.service.SysLogService;
import io.github.util.PageUtils;
import io.github.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: Max
 * @Date: 2019/10/8 17:21
 */

@RestController
@RequestMapping("/admin/logs")
public class SysLogController extends AbstractController {

    @Autowired
    private SysLogService logService;

    @RequestMapping("/list")
    public R list(@RequestBody JSONObject jsonObject){
        Integer offset = jsonObject.getInteger("offset");
        Integer limit = jsonObject.getInteger("limit");
        Integer action = jsonObject.getInteger("action");
        String userName = jsonObject.getString("userName");
        String startTime = jsonObject.getString("startTime");
        String endTime = jsonObject.getString("endTime");
        Page<SysLogEntity> list = logService.query(offset,limit,startTime,endTime,action,userName);

        PageUtils pageUtil = new PageUtils(list.getRecords(),list.getTotal(),list.getSize(),list.getCurrent());
        return R.ok().put("page",pageUtil);
    }
}
